package JackSu.aobing;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class ThreadPoolTest implements Runnable {

    private int count;

    @Override
    public void run() {
        for(int i = 0;i < 10000;i++){
            count++;
        }
        System.out.println("count=" + count);
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
//        ExecutorService executorService = Executors.newCachedThreadPool();
//        ExecutorService executorService = Executors.newFixedThreadPool(5);
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        ThreadPoolTest threadPoolTest = new ThreadPoolTest();
        for(int i = 0;i < 15;i++) {
            executorService.execute(threadPoolTest);
        }
        executorService.shutdown();
    }
}
